/** 
 * @Title:  PhoneRegisteredDialog.java 
 * @author:  Abtswiath丶lxy
 * @data:  2016年6月8日 下午5:55:35 <创建时间>
 * 
 * @history：<以下是历史记录>
 *
 * @modifier: <修改人>
 * @modify date: 2016年6月8日 下午5:55:35 <修改时间>
 * @log: <修改内容>
 *
 * @modifier: <修改人>
 * @modify date: 2016年6月8日 下午5:55:35 <修改时间>
 * @log: <修改内容>
 */
package com.sunmi.usercenter.ui.component;

import com.sunmi.usercenter.R;
import com.sunmi.usercenter.ui.activity.fragment.RegisterFragment;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/** 
 * TODO<请描述这个类是干什么的> 
 * @author Abtswiath丶lxy
 * @versionCode 1 <每次修改提交前+1>
 */
public class PhoneRegisteredDialog extends Dialog {
	
	private Context mContext;
	private static PhoneRegisteredDialog phoneRegisteredDialog = null;

	public PhoneRegisteredDialog(Context context) {
		super(context);
		this.mContext = context;
	}
	public PhoneRegisteredDialog(Context context, int theme) {
		super(context, theme);
		this.mContext = context;
	}
	
	public static PhoneRegisteredDialog createDialog(Context context){
		phoneRegisteredDialog = new PhoneRegisteredDialog(context, R.style.defaultDialogStyle);
		phoneRegisteredDialog.setContentView(R.layout.dialog_phone_registered);
		phoneRegisteredDialog.getWindow().getAttributes().gravity = Gravity.CENTER; //居中
		phoneRegisteredDialog.setCanceledOnTouchOutside(true); //点击空白不取消
		phoneRegisteredDialog.setCancelable(false); //点击返回按钮不取消
		return phoneRegisteredDialog;
	}
	
	public PhoneRegisteredDialog setText(String phone){
		TextView textView = (TextView)phoneRegisteredDialog.findViewById(R.id.txt_phone);
		textView.setText(phone);
		return phoneRegisteredDialog;
	}
	
	public PhoneRegisteredDialog setTwoOnClickListener(final TwoToDoOnClickListener twoToDoOnClickListener,String forWhatRegister){
		LinearLayout mLinChangePhone = (LinearLayout) phoneRegisteredDialog.findViewById(R.id.line_change_phone);
		LinearLayout mLinThisPhoneLogin = (LinearLayout) phoneRegisteredDialog.findViewById(R.id.line_this_phone_login);
		TextView textView1 = (TextView) phoneRegisteredDialog.findViewById(R.id.txt_to_changphone);
		TextView textView2 = (TextView) phoneRegisteredDialog.findViewById(R.id.txt_to_login);
		if(forWhatRegister.equals(RegisterFragment.EMAIL)){
			textView1.setText(mContext.getString(R.string.change_email_to_register));
			textView2.setText(mContext.getString(R.string.use_this_email_to_login));
		}else{
			textView1.setText(mContext.getString(R.string.change_phone_to_register));
			textView2.setText(mContext.getString(R.string.use_this_phone_to_login));
		}
		mLinChangePhone.setOnClickListener(new android.view.View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				twoToDoOnClickListener.changePhone();
			}
		});
		mLinThisPhoneLogin.setOnClickListener(new android.view.View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				twoToDoOnClickListener.thisPhoneLogin();
			}
		});
		return phoneRegisteredDialog;
	}
	
	public interface TwoToDoOnClickListener{
		public void changePhone();
		public void thisPhoneLogin();
	}
	
	@Override
	public void dismiss() {
		super.dismiss();
		if(phoneRegisteredDialog!=null){
			phoneRegisteredDialog = null;
		}
		if(mContext!=null){
			mContext = null;
		}
	}

}
